package cn.wolfcode.p2p.business.domain;

import cn.wolfcode.p2p.base.domain.BaseDomain;
import cn.wolfcode.p2p.base.domain.LoginInfo;
import cn.wolfcode.p2p.util.Constant;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 还款计划
 */
@Setter
@Getter
public class PaymentSchedule extends BaseDomain{
    /**
     * 最后还款截止日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date deadline;
    /**
     * 实际还款日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date payDate;
    /**
     * 本期还款本息
     */
    private BigDecimal totalAmount;
    /**
     * 本期还款本金
     */
    private BigDecimal principal;
    /**
     * 本期还款利息
     */
    private BigDecimal interest;
    /**
     * 当前还款期数
     */
    private Integer monthIndex;
    /**
     * 本期还款状态
     */
    private Integer state = Constant.PAYMENT_STATE_NORMAL;
    /**
     * 借款类型
     */
    private Integer bidRequestType = Constant.BIDREQUEST_TYPE_NORMAL;
    /**
     * 还款类型
     */
    private Integer returnType;
    /**
     * 借款对象id
     */
    private Long bidRequestId;
    /**
     * 借款人
     */
    private LoginInfo borrowUser;
    /**
     * 借款标题
     */
    private String bidRequestTitle;

    /**
     * 逾期滞纳金,本期最高滞纳金为一倍的应还总额
     */
    private BigDecimal latePayment = Constant.ZERO;


    /**
     * 收款明细
     */
    private List<PaymentScheduleDetail> paymentScheduleDetailLists = new ArrayList<>();

    /**
     * 状态的名称
     */
    public String getStateDisplay(){
        switch (state){
            case Constant.PAYMENT_STATE_NORMAL: return "待还款";
            case Constant.PAYMENT_STATE_DONE: return "已还";
            case Constant.PAYMENT_STATE_OVERDUE: return "逾期";
        }
        return "状态异常";
    }

    public BigDecimal getTotalAmountAddLatePayment(){
        return latePayment.add(totalAmount);
    }

}